home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / scrnsav2.arc / SCRNSAV2.ASM next >
Assembly Source File  |  1985-04-06  |  6KB  |  204 lines

  1. ;    ---------------------------------------------------------------
  2. ;    Program SCRNSAVE.COM to blank the screen after two minutes of
  3. ;    inactivity.  This program is based on the program BLANK.COM
  4. ;    submitted by Christopher Wiley in PC World Volume 2 Number 4
  5. ;    and later modified by Steve Cook and printed in PC World Volume
  6. ;    2 Number 11.  Subsequent modifications include the addition of
  7. ;    a message to the user and use of INT 21H function 31H instead
  8. ;    of INT 27H.
  9. ;
  10. ;    This utility works well with both the IBM Color and Monochrome
  11. ;    Displays -- even after issuing a MODE command to change
  12. ;    displays after this program has run!
  13. ;    ---------------------------------------------------------------
  14. ;
  15. ; Define the code segment, and set things up for a .COM program
  16. ;
  17. CSEG    SEGMENT PARA PUBLIC 'CODE'
  18.     ASSUME CS:CSEG,DS:CSEG
  19. ;
  20. ; Programs which are to be put through EXE2BIN must start at address
  21. ; 100H so...
  22. ;
  23.     ORG    100H
  24. ;
  25. START:    JMP     GO        ; jump around the data area
  26. ;
  27. SWFLAG    DB    0        ; video not switched off (1 if we did)
  28. KEYFLAG    DB    0        ; no key input nor display since video off
  29. COUNT    DW    0        ; timer count
  30. ;
  31. ADDR_6845    EQU    63H    ; CRT control port base address
  32. CRT_MODE_SET    EQU    65H    ; current state of CRT mode register
  33. ;
  34. ;
  35. ; timer tick interrupt with occurs 18.2 times per second
  36. ;
  37. TICKER:
  38.     STI            ; restore interrupts
  39.     PUSH    AX        ; save registers
  40.     PUSH    DS
  41.     PUSH    CS        ; set DS to code segment
  42.     POP    DS
  43.     CMP    SWFLAG,0    ; is the video already off ?
  44.     JNE    T01        ; yes, jump to T01
  45.     INC    COUNT        ; no, keep counting clock pulses
  46.     CMP    COUNT,0888H    ;   until we get to 2 minutes
  47.     JNAE    T02        ; if we hit limit, jump to T02
  48.     MOV    COUNT,0        ; yes, reset counter to zero
  49.     PUSH    DX        ; save these registers too
  50.     PUSH    ES        ; Now to switch the video off
  51.     MOV    AX,0040H    ; (base address of ROM data area)
  52.     MOV    ES,AX
  53.     MOV    DX,ES:ADDR_6845    ; Get base address of video controller
  54.     ADD    DX,4        ; point to controller's mode register
  55.     MOV    AL,ES:CRT_MODE_SET ;Get current mode settings
  56.     AND    AL,11110111B    ; Clear the video enable bit to
  57.     OUT    DX,AL        ; turn off the video.
  58.     POP    ES
  59.     POP    DX
  60.     MOV    SWFLAG,1    ; flag video as switched off
  61.     JMP    SHORT T02    ; standard exit
  62. T01:
  63.     CMP    KEYFLAG,0    ; We have switched off.  Has a key been
  64.                 ; pressed or attempt been made to     DS
  65.     JE    T02        ; display a character since then?  No.
  66.     PUSH    DX        ; Yes.  Restore video signal
  67.     PUSH    ES
  68.     MOV    AX,0040H    ; First, point to the ROM data area
  69.     MOV    ES,AX
  70.     MOV    DX,ES:ADDR_6845    ; Get base address of video controller
  71.     ADD    DX,4        ; and point to controller mode register
  72.     MOV    AL,ES:CRT_MODE_SET ; Get the old mode settings and
  73.     OUT    DX,AL        ; restore them
  74.     POP    ES
  75.     POP    DX
  76.     MOV    KEYFLAG,0    ; Reset the flags as: No key in/video
  77.     MOV    SWFLAG,0    ; not switched
  78.     MOV    COUNT,0        ; reset (again) count to 0
  79. T02:
  80.     POP    DS        ; standard exit.  Restore Used Registers
  81.     POP    AX        ; and process whatever was at INT 1CH
  82.     INT    60H        ; before this program was invoked
  83.     IRET
  84. ;
  85. ; The user has pressed a key on the keyboard
  86. ;
  87. KEY_IN:
  88.     STI            ; restore interrupts
  89.     PUSH    AX        ; save registers
  90.     PUSH    DS
  91.     PUSH    CS        ; set DS to code segment
  92.     POP    DS
  93.     CMP    SWFLAG,0    ; is the video already off ?
  94.     JE    K01        ; no
  95.     MOV    KEYFLAG,1    ; Yes, set theflag that we got a key
  96.     INT    1CH
  97. K01:
  98.     MOV    COUNT,0        ; yes, reset counter to zero
  99.     POP    DS        ; restore the saved register and inform
  100.     POP    AX        ; the system by causing the equivalent
  101.     INT    61H        ; of an INT 09H in this program
  102.     IRET
  103. ;
  104. ; The system wants to write something to the screen
  105. ;
  106. VIDEO_OUT:
  107.     STI            ; restore interrupts
  108.     PUSH    AX        ; save registers
  109.     PUSH    DS
  110.     PUSH    CS        ; set DS to code segment
  111.     POP    DS
  112.     CMP    SWFLAG,0    ; is the video already off ?
  113.     JE    V01        ; no
  114.     MOV    KEYFLAG,1    ; Yes, set the flag that we want it on
  115.     INT    1CH
  116. V01:
  117.     MOV    COUNT,0        ; yes, reset counter to zero
  118.     POP    DS        ; restore the saved register and inform
  119.     POP    AX        ; the system by causing the equivalent
  120.     INT    62H        ; of an INT 10H in this program
  121.     IRET
  122. ;
  123. END_PR:                ; used to determine length of program
  124. ;
  125. GO:
  126.     MOV    AH,35H        ; get address of 1C vector (timer 18.2
  127.     MOV    AL,1CH        ; timer per second frequency)
  128.     INT    21H
  129.     PUSH    ES         ; move ES:BX to DS:DX
  130.     PUSH    BX
  131.     POP    DX
  132.     POP    DS
  133.     MOV     AH,25H        ; set into interrupt 60H as replacement
  134.     MOV    AL,60H
  135.     INT    21H
  136. ;
  137.     MOV    AH,35H        ; Do same for keyboard interrupt
  138.     MOV    AL,09H
  139.     INT    21H
  140.     PUSH    ES
  141.     PUSH    BX
  142.     POP    DX
  143.     POP    DS
  144.     MOV     AH,25H        ; set into interrupt 61H as replacement
  145.     MOV    AL,61H
  146.     INT    21H
  147. ;
  148.     MOV    AH,35H        ; Do same for video interrupt
  149.     MOV    AL,10H
  150.     INT    21H
  151.     PUSH    ES
  152.     PUSH    BX
  153.     POP    DX
  154.     POP    DS
  155.     MOV     AH,25H        ; set into interrupt 62H as replacement
  156.     MOV    AL,62H
  157.     INT    21H
  158. ;
  159.     PUSH    CS        ; now set new values in the vector 1CH
  160.     POP    DS
  161.     MOV    DX,OFFSET TICKER
  162.     MOV     AH,25H
  163.     MOV    AL,1CH
  164.     INT    21H        ; as timer tick interrupt
  165. ;
  166.     PUSH    CS        ; now set new values in the vector 09H
  167.     POP    DS
  168.     MOV    DX,OFFSET KEY_IN
  169.     MOV     AH,25H
  170.     MOV    AL,09H
  171.     INT    21H        ; as keyboard interrupt
  172. ;
  173.     PUSH    CS        ; now set new values in the vector 10H
  174.     POP    DS
  175.     MOV    DX,OFFSET VIDEO_OUT
  176.     MOV     AH,25H
  177.     MOV    AL,10H
  178.     INT    21H        ; as video interrupt
  179. ;
  180.     PUSH    CS        ; now send message to screen
  181.     POP    DS
  182.     MOV    DX,OFFSET MESSAGE
  183.     MOV     AH,09H
  184.     INT    21H
  185. ;
  186.     PUSH    CS        ; set DS to CS
  187.     POP    DS
  188.     MOV    DX,OFFSET END_PR ; Set DX to length of modules
  189.     SHR    DX,1        ; to remain resident and divide
  190.     SHR    DX,1        ; by 16 to get the length in
  191.     SHR    DX,1        ; paragraphs
  192.     SHR    DX,1
  193.     INC    DX
  194.     MOV    AH,31H        ; invoke DOS function to leave
  195.     MOV    AL,00        ; terminate and leave these
  196.     INT    21H        ; modules resident
  197. ;
  198. MESSAGE DB    'Screen saver in effect with a two-minute timeout'
  199. CRLF    DB    0DH,0AH
  200.     DB    '$'
  201. ;
  202. CSEG    ENDS
  203.     END    START
  204.